//
//  WeatherViewController.m
//  ToWhere
//
//  Created by dllo on 15/11/19.
//  Copyright © 2015年 www.TE.com. All rights reserved.
//

#import "WeatherViewController.h"

@interface WeatherViewController ()
@property (nonatomic, retain) NSArray *array;
@property (nonatomic, retain) UILabel *currentTmp;
@property (nonatomic, retain) UILabel *currentWeather;
@property (nonatomic, retain) UILabel *alertLabel;
@property (nonatomic, retain) UILabel *Bodyfeeling;
@property (nonatomic, retain) UILabel *humidity;
@property (nonatomic, retain) UILabel *wind;
@property (nonatomic, retain) UILabel *uv;
@end

@implementation WeatherViewController
- (void)dealloc
{
    [_currentTmp release];
    [_currentWeather release];
    [_alertLabel release];
    [_Bodyfeeling release];
    [_humidity release];
    [_wind release];
    [_uv release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    //self.view.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.9];
        [self initLabel];
}

- (void)initLabel{

    NSString *str = nil;
    if ([[self.weather.now objectForKey:@"nowweather"] containsString:@"多云"]) {
        str = @"duoyun.jpg";
        
    }else if ([[self.weather.now objectForKey:@"nowweather"] containsString:@"晴"]){
        str = @"wip_bk_sunny.jpg";
    }else if ([[self.weather.now objectForKey:@"nowweather"] containsString:@"雨"]){
        str = @"xiayu.jpg";
        
    }else if ([[self.weather.now objectForKey:@"nowweather"] containsString:@"雪"]){
        str = @"xiaxue.jpg";
    }else{
        str = @"yintian.jpg";
    
    }

    
    UIImageView *imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:str]];
    imageV.frame = CGRectMake(0, 0, 375 *kWidth, 667 *kHeight);
    [self.view addSubview:imageV];
    UIView *viewback = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 375 *kWidth, 667 *kHeight)];
    viewback.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.2];
    [imageV addSubview:viewback];
    self.currentTmp = [[UILabel alloc] initWithFrame:CGRectMake(120 *kWidth, 100 *kHeight, 135 *kWidth, 80 *kHeight)];
    self.currentTmp.textAlignment = NSTextAlignmentCenter;
    self.currentTmp.textColor = [UIColor whiteColor];
    self.currentTmp.font = [UIFont systemFontOfSize:50 *kWidth];
    self.currentTmp.text = [self.weather.now objectForKey:@"temp"];
    [viewback addSubview:self.currentTmp];
    [_currentTmp release];
    
    self.currentWeather = [[UILabel alloc] initWithFrame:CGRectMake(120 *kWidth, 180 *kHeight, 135 *kWidth, 25 *kHeight)];
    self.currentWeather.font = [UIFont systemFontOfSize:17 *kWidth];
    self.currentWeather.textAlignment = NSTextAlignmentCenter;
    self.currentWeather.textColor = [UIColor whiteColor];
    self.currentWeather.text = [[self.weather.weatherinfo objectForKey:@"weather"][1] objectForKey:@"dayweather"];
    [viewback addSubview:_currentWeather];
    [_currentWeather release];
    
    self.alertLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 220 *kHeight, 375 *kWidth, 20 *kHeight)];
    self.array = [NSArray arrayWithObjects:@"天气较冷，穿暖和点吧", @"今天天气不错，外出游玩吧！", @"天气较热，注意防晒哦！", nil];

    if ([[self.weather.now objectForKey:@"temp"]integerValue] < 15){
    
        self.alertLabel.text = self.array[0];
    }else if ([[self.weather.now objectForKey:@"temp"]integerValue] < 25){
        self.alertLabel.text = self.array[1];
    }else{
    
        self.alertLabel.text = self.array[2];
    }
    
    self.alertLabel.textColor = [[UIColor cyanColor]colorWithAlphaComponent:0.8];
    self.alertLabel.font = [UIFont systemFontOfSize:15 *kWidth];
    self.alertLabel.textAlignment = NSTextAlignmentCenter;
    [viewback addSubview:_alertLabel];
    [_alertLabel release];
    
    UILabel *hum = [[UILabel alloc] initWithFrame:CGRectMake(80 *kWidth, 265 *kHeight, 80 *kWidth, 25 *kHeight)];
    hum.font = [UIFont systemFontOfSize:17 *kWidth];
    hum.textColor = [UIColor whiteColor];
    hum.text = @"湿度";
    [viewback addSubview:hum];
    [hum release];
    
    self.humidity = [[UILabel alloc] initWithFrame:CGRectMake(195 *kWidth, 265 *kHeight, 100 *kWidth, 25 *kHeight)];
    self.humidity.font = [UIFont systemFontOfSize:17 *kWidth];
    self.humidity.textColor = [UIColor whiteColor];
    self.humidity.textAlignment = NSTextAlignmentRight;
    self.humidity.text = [NSString stringWithFormat:@"%@％",[self.weather.now objectForKey:@"sd"]];
    [viewback addSubview:_humidity];
    [_humidity release];
    
    UILabel *linehum = [[UILabel alloc] initWithFrame:CGRectMake(80 *kWidth,  293 *kHeight, 215 *kWidth, 2 *kHeight)];
    linehum.backgroundColor = [UIColor colorWithWhite:0.880 alpha:1.000];
    [viewback addSubview:linehum];
    [linehum release];
    
    UILabel *wind = [[UILabel alloc] initWithFrame:CGRectMake(80 *kWidth, 328 *kHeight, 80 *kWidth, 25 *kHeight)];
    wind.text = @"风";
    wind.textColor = [UIColor whiteColor];
    wind.font = [UIFont systemFontOfSize:17 *kWidth];
    [viewback addSubview:wind];
    [wind release];
    
    self.wind = [[UILabel alloc] initWithFrame:CGRectMake(195 *kWidth, 328 *kHeight, 100 *kWidth, 25 *kHeight)];
    self.wind.textColor = [UIColor whiteColor];
    self.wind.textAlignment = NSTextAlignmentRight;
    self.wind.text = [NSString stringWithFormat:@"%@%@",[self.weather.now objectForKey:@"wd"],[self.weather.now objectForKey:@"ws"]];
    [viewback addSubview:_wind];
    self.wind.font = [UIFont systemFontOfSize:17 *kWidth];
    [_wind release];
    
    UILabel *lineWd = [[UILabel alloc] initWithFrame:CGRectMake(80 *kWidth, 356 *kHeight, 215 *kWidth, 2 *kHeight)];
    lineWd.backgroundColor = [UIColor colorWithWhite:0.880 alpha:1.000];
    [viewback addSubview:lineWd];
    [lineWd release];
    
    UILabel  *uv = [[UILabel alloc] initWithFrame:CGRectMake(80 *kWidth, 391 *kHeight, 80 *kWidth, 25 *kHeight)];
    uv.textColor = [UIColor whiteColor];
    uv.text = @"紫外线";
    uv.font = [UIFont systemFontOfSize:17 *kWidth];
    [viewback addSubview:uv];
    [uv release];
    
    self.uv = [[UILabel alloc] initWithFrame:CGRectMake(195 *kWidth, 391 *kHeight, 100 *kWidth, 25 *kHeight)];
    self.uv.textColor = [UIColor whiteColor];
    self.uv.textAlignment = NSTextAlignmentRight;
    self.uv.font = [UIFont systemFontOfSize:17 *kWidth];
    self.uv.text = [self.weather.now objectForKey:@"uv"];
    [viewback addSubview:_uv];
    [_uv release];
    
    UILabel *lineuv = [[UILabel alloc] initWithFrame:CGRectMake(80 *kWidth, 419 *kHeight, 215 *kWidth, 2 *kHeight)];
    lineuv.backgroundColor = [UIColor colorWithWhite:0.880 alpha:1.000];
    [viewback addSubview:lineuv];
    [lineuv release];


}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [self dismissViewControllerAnimated:YES completion:nil];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
